import java.util.ArrayList;
import java.util.List;

/**
 * @author ZJR
 * @since 2021/02/25
 * 拨号键盘demo
 */
public class DigitToLettersDemo {

    private static String[] buttons = {"", "", "ABC", "DEF", "GHI", "JKL", "MNO",
            "PQRS", "TUV", "WXYZ"};

    public static void main(String[] args) {
        int[] digits = {2,3};
        List<String> result = digitToLetters(digits);
        for (String letter : result) {
            System.out.print(letter + " ");
        }
    }

    public static List<String> digitToLetters(int[] digitArray) {
        if (digitArray == null || digitArray.length == 0) {
            return new ArrayList<>();
        }
        List<String> result = new ArrayList<>();
        result.add("");
        for (int digit : digitArray) {
            String letters = buttons[digit];
            List<String> tempResult = new ArrayList<>();
            for (String resultItem : result) {
                for (int k = 0; k < letters.length(); k++) {
                    tempResult.add(resultItem + letters.charAt(k));
                }
            }
            result = tempResult;
        }
        return result;
    }
}

